package work.chenbo.mybatis.customize.config;

import org.dom4j.DocumentException;
import work.chenbo.mybatis.customize.session.SqlSessionFactory;
import work.chenbo.mybatis.customize.session.impl.DefaultSqlSessionFactory;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @author ChenBo
 * @className SqlSessionFactoryBuilder
 * @date 2020/12/24
 */
public class SqlSessionFactoryBuilder {

    private Configuration configuration;

    public SqlSessionFactoryBuilder(){
        this.configuration = new Configuration();
    }

    public SqlSessionFactory builder(InputStream inputStream) throws DocumentException, PropertyVetoException, ClassNotFoundException {
        XmlConfigurationBuilder xmlConfigurationBuilder = new XmlConfigurationBuilder(configuration);
        xmlConfigurationBuilder.parseConfiguration(inputStream);
        return new DefaultSqlSessionFactory(configuration);
    }
}
